-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: refactor to avoid mutation of global by a loader #46220
Conversation
// Artificial timeout to keep the event loop alive. | ||
// https://bugs.chromium.org/p/v8/issues/detail?id=13238 | ||
// TODO(targos) Remove when V8 issue is resolved. | ||
const timeout = setTimeout(() => {}, 1_000); | ||
await Atomics.waitAsync(int32, 0, 0).value; | ||
clearTimeout(timeout); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc @joyeecheung this is related to https://bugs.chromium.org/p/v8/issues/detail?id=13238 / #44409
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW the current implementation of #44710 relies on Atomics.waitAsync
not keeping the event loop alive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aduh95 What would be your expectation? Should Atomics.waitAsync
keep the event loop alive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally there would be a way to control it, like you can opt-out for setTimeout
. My expectation was that it would not keep the event loop alive, but I could see how that can also be annoying for some (most?) use cases. Does it also not keep the event loop alive if you add a fourth timeout parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fourth timeout parameter doesn't change the behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so far the vibes I got is that "this is host-defined" i.e. Node.js gets to decide if the timeout parameter keeps the event loop alive (neither the ES or the Web specs have this "shut down the loop on completion" concept, they just assume the agent runs forever until it gets told to shut down, so we are on our own here), but also if we want to implement that, V8 needs to provide a way in the platform API for canceling a delayed task (so that when it wakes up before the timeout, we get notified that there is no need to keep the event loop alive for it anymore), which is probably too much complexity, so to be lazy we can also just keep the things the way they are (not let the time out keep the event loop alive, which some may argue is also their expected behavior, like how an unresolved promise doesn't keep the thread alive).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. FYI in nodejs/loaders#124 (reply in thread) I’m discussing redesigning globalPreload
, possibly by creating a new API to handle the communications port stuff and getting rid of the “sloppy mode script” aspect of globalPreload
now that we have --import
. I was thinking that that could come after we land off-thread, though, and possibly even after making loaders stable (I would keep globalPreload
as experimental but mark resolve
and load
as stable).
@targos I assume this new version of this test passes both on |
This makes the test compatible with off-thread loaders. Co-Authored-By: Geoffrey Booth <webadmin@geoffreybooth.com>
1cc9f59
to
825261e
Compare
@GeoffreyBooth Yes, it passes on both branches. |
Commit Queue failed- Loading data for nodejs/node/pull/46220 ✔ Done loading data for nodejs/node/pull/46220 ----------------------------------- PR info ------------------------------------ Title test: refactor to avoid mutation of global by a loader (#46220) Author Michaël Zasso (@targos) Branch targos:fix-resolve-type -> nodejs:main Labels test, esm, author ready Commits 1 - test: refactor to avoid mutation of global by a loader Committers 1 - Michaël Zasso PR-URL: https://github.com/nodejs/node/pull/46220 Reviewed-By: Antoine du Hamel Reviewed-By: Geoffrey Booth ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/46220 Reviewed-By: Antoine du Hamel Reviewed-By: Geoffrey Booth -------------------------------------------------------------------------------- ℹ This PR was created on Sun, 15 Jan 2023 12:07:37 GMT ✔ Approvals: 2 ✔ - Antoine du Hamel (@aduh95) (TSC): https://github.com/nodejs/node/pull/46220#pullrequestreview-1249340907 ✔ - Geoffrey Booth (@GeoffreyBooth) (TSC): https://github.com/nodejs/node/pull/46220#pullrequestreview-1249358333 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2023-01-15T21:13:00Z: https://ci.nodejs.org/job/node-test-pull-request/48993/ ⚠ Commits were pushed after the last Full PR CI run: ⚠ - test: refactor to avoid mutation of global by a loader - Querying data for job/node-test-pull-request/48993/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/3939092857 |
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
Landed in cf8c699 |
This makes the test compatible with off-thread loaders. Co-Authored-By: Geoffrey Booth <webadmin@geoffreybooth.com> PR-URL: #46220 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
This makes the test compatible with off-thread loaders. Co-Authored-By: Geoffrey Booth <webadmin@geoffreybooth.com> PR-URL: #46220 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
This makes the test compatible with off-thread loaders. Co-Authored-By: Geoffrey Booth <webadmin@geoffreybooth.com> PR-URL: #46220 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
This makes the test compatible with off-thread loaders.
/cc @GeoffreyBooth @aduh95